package cc.jorange.service.init;

import cc.jorange.bean.Poster;
import cc.jorange.bean.Work;
import cc.jorange.common.Clock;
import cc.jorange.dao.PosterDao;
import cc.jorange.dao.WorkDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 添加数据
 */
@Component
public class InitDto {

    private Clock clock = Clock.DEFAULT;

    @Autowired
    private WorkDao workDao;
    @Autowired
    private PosterDao posterDao;

    @PostConstruct
    public void init() {
        this.works();
        this.poster();
    }

    private void poster() {
        this.createPoster(25, "", "d", "image/poster/gj.png", 79L, 5);
        this.createPoster(26, "", "d", "image/poster/tlbb.png", 80L, 4);
        this.createPoster(27, "", "d", "image/poster/msnxs.png", 81L, 3);
        this.createPoster(28, "", "d", "image/poster/qqxw.png", 82L, 2);
    }

    private void works() {
        this.createWork(79L, "《国家》", "YHBOYS", "", "", "", "", "<iframe width=\"100%\" height=\"563px\" src='http://player.youku.com/embed/XMzA1NDY1Mzc4NA==' frameborder=0 'allowfullscreen'></iframe>", "2017/gj.png", "type", "2017", "HOT,NEW");
        this.createWork(80L, "《天龙八部》", "杨宗纬", "", "", "", "", "<embed src=\"https://imgcache.qq.com/tencentvideo_v1/playerv3/TPout.swf?max_age=86400&v=20161117&vid=b00239dem44&auto=0\" allowFullScreen=\"true\" quality=\"high\" width=\"100%\" height=\"563px\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\"></embed>", "2017/tlbb.png", "type", "2017", "HOT,NEW");
        this.createWork(81L, "《美少年学社》", "美少年学社", "", "", "", "", "<iframe width=\"100%\" height=\"563px\" src='http://player.youku.com/embed/XMjc2MTU0NTEwOA==' frameborder=0 'allowfullscreen'></iframe>", "2017/msnxs.png", "type", "2017", "HOT,NEW");
        this.createWork(82L, "《QQ炫舞手游2017宣传片》", "张皓宸", "", "", "", "", "<embed src=\"https://imgcache.qq.com/tencentvideo_v1/playerv3/TPout.swf?max_age=86400&v=20161117&vid=i0023mh3zr0&auto=0\" allowFullScreen=\"true\" quality=\"high\" width=\"100%\" height=\"563px\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\"></embed>", "2017/qqxw.png", "type", "2017", "HOT,NEW");
    }

    private void createPoster(long id, String title, String description, String img, Long workId, int score) {
        Poster p = new Poster();
        p.setId(id);
        p.setTitle(title);
        p.setImg(img);
        p.setWorkId(workId);
        p.setDescription(description);
        p.setScore(score);
        p.setTs(clock.getCurrentDate());
        posterDao.save(p);
    }

    private void createWork(long id, String title, String author, String company, String description, String blog, String team, String url, String img, String type, String createDate, String tags) {
        Work work = new Work();
        work.setId(id);
        work.setTitle(title);
        work.setAuthor(author);
        work.setCompany(company);
        work.setDescription(description);
        work.setBlog(blog);
        work.setTeam(team);
        work.setUrl(url);
        work.setImg(img);
        work.setType(type);
        work.setCreateDate(createDate);
        work.setTags(tags);
        work.setTs(clock.getCurrentDate());
        workDao.save(work);
    }

}
